﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
public partial class WebSite_s_paper : System.Web.UI.Page
{
    public static int QuestionId = 0;
    string userid;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] == null || Session["UserIdentity"].ToString() != "0")
        {
            Response.Redirect("Default.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;
        }
        else userid = Session["UserId"].ToString();
        try
        {
            QuestionId = Convert.ToInt32(Request.QueryString["id"]);
            string path = " ";
            DataSet set = new DataSet();
            QuestionnaireHandler Qhandler = new QuestionnaireHandler();
            DataSet ds = new DataSet();
            ds = Qhandler.GetQuestionById(QuestionId);
            path = ds.Tables[0].Rows[0][4].ToString();
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlNodeReader reader = new XmlNodeReader(doc);
            set.ReadXml(reader);
            reader.Close();
            this.Label5.Text = set.Tables[0].Rows[0][2].ToString();
            this.Label1.Text = set.Tables[0].Rows[0][3].ToString();
            this.Label2.Text = set.Tables[0].Rows[0][4].ToString();
            this.Label3.Text = set.Tables[0].Rows[0][5].ToString();
            this.Label4.Text = set.Tables[0].Rows[0][6].ToString();
            return;
        }
        catch(Exception ex)
        {
            //跳转到错误处理页面。
            Session["ErrorMessage"] = ex.Message;
            Session["AtPage"] = "s_paper.aspx";
            Response.Redirect("s_error.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            string UserId = (string)Session["UserId"];
            string Result = " ";
            if (this.RadioButton1.Checked)
            {
                Result = "1";
            }
            else if (this.RadioButton2.Checked)
            {
                Result = "2";
            }
            else if (this.RadioButton3.Checked)
            {
                Result = "3";
            }
            else
            {
                Result = "4";
            }
            QuestionnaireHandler Qhandler = new QuestionnaireHandler();
            Qhandler.AddQuestionnaireResult(QuestionId, UserId, 1, Result);
            if (Qhandler.flag == 1)
            {
                Response.Redirect("error.aspx",false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
                return;            
            }
            else
            {
                Response.Redirect("s_paper_show.aspx?id=" + QuestionId,false);
                HttpContext.Current.ApplicationInstance.CompleteRequest();
                return;
            }
        }
        catch(Exception ex)
        {
            //跳转到错误处理页面。
            Session["ErrorMessage"] = ex.Message;
            Session["AtPage"] = "s_paper.aspx";
            Response.Redirect("s_error.aspx", false);
            HttpContext.Current.ApplicationInstance.CompleteRequest();
            return;    
        }
    }
}
